<?php
include_once 'language/vn.php';
include_once 'language/url.php';
include_once '../connection/connection_database.php';
include_once 'model/user/user_create.php';
$user = new users();

$error = $_GET["e"];
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="description" content="Reflect Template" />
        <title>Bravolaw Login Page</title>
        <link rel="stylesheet" href="<?php echo $url["home"] ?>/css/style_all.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="<?php echo $url["home"] ?>/css/style1.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="<?php echo $url["home"] ?>/css/jquery-ui.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="<?php echo $url["home"] ?>/css/jquery.wysiwyg.css" type="text/css" media="screen" />
        <script type="text/javascript" src="<?php echo $url["home"] ?>/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="<?php echo $url["home"] ?>/js/jqueryNoconfig.js"></script>
        <script type="text/javascript" src="<?php echo $url["home"] ?>/checkForm/check_validate.js"></script>
    </head>

    <body class="nobackground">
        <?php
        if ($user->FillOneByLevel()) {
            ?>
            <div id="login">
                <h2 class="loginheading"><?= $phrase["login"] ?></h2>
                <div class="icon_login ie6fix"></div>

                <form id="login-form" action="<?php echo $url["home"] ?>/controller/user/user_login.php" method="post">
                    <p>
                        <label for="name"><?= $phrase["username"] ?></label>
                        <input class="input-medium" type="text" value="" name="username" id="username"/>
                    </p>
                    <p>
                        <label for="password"><?= $phrase["password"] ?></label>
                        <input class="input-medium" type="password" value="" name="password" id="password"/>
                    </p>

                    <p class="remember">
                        <input type="checkbox" value="1" name="save_user" id="save_user"/>
                        <label for="checkbox1" class="inline"><?= $phrase["remember"] ?></label>
                    </p>
                    <div class="forgot_pw"><a href="index-2.html"><?= $phrase["forgot"] ?></a></div>
                    <p class="clearboth">
                        <input class="button" name="submit" type="submit" value="<?= $phrase["login"] ?>" onclick="return isCheckLogin(this.form)"/>
                    </p>
                </form>
            </div>

            <div class="login_message message error" id="error" style="display: none">
            </div>
        <?php } else { ?>
            <div id="create_admin">
                <h2 class="loginheading"><?= $phrase["create_admin"] ?></h2>
                <div class="icon_login ie6fix"></div>

                <form id="login-form" action="<?php echo $url["home"] ?>/controller/user/user_login.php" method="post">
                    <p>
                        <label for="name"><?= $phrase["username"] ?></label>
                        <input class="input-medium" type="text" value="" name="username" id="username"/>
                    </p>
                    <p>
                        <label for="password"><?= $phrase["password"] ?></label>
                        <input class="input-medium" type="password" value="" name="password" id="password"/>
                    </p>
                    <p>
                        <label for="password"><?= $phrase["confirm_password"] ?></label>
                        <input class="input-medium" type="password" value="" name="repassword" id="repassword"/>
                    </p>
                    <p>
                        <label for="fullname"><?= $phrase["fullname"] ?></label>
                        <input class="input-medium" type="text" value="" name="fullname" id="fullname"/>
                    </p>

                    <p>
                        <label for="email"><?= $phrase["email"] ?></label>
                        <input class="input-medium" type="text" value="" name="email" id="email"/>
                    </p>

                    <p>
                        <label for="phone"><?= $phrase["phone"] ?></label>
                        <input class="input-medium" type="text" value="" name="phone" id="phone"/>
                    </p>
                    <p class="clearboth">
                        <input class="button" name="create" type="submit" value="<?= $phrase["create"] ?>" onclick="return isCheckCreateAdmin(this.form)"/>
                    </p>
                </form>
            </div>

            <div class="create_message message error" id="error" style="display: none">
            </div>
        <?php } ?>
    </body>
</html>
<script>
<?php if ($error == 'error') { ?>
        $('#error').show();
        $('#error').html('<p>Username or Password sai.</p>');
<?php } else if($error == 'err-create'){ ?>
        $('#error').show();
        $('#error').html('<p>Username đã tồn tại.</p>');
<?php } else if($error == 'err-insert') { ?>
        $('#error').show();
        $('#error').html('<p>Insert thất bại.</p>');
<?php } ?>
    
    $(document).ready(function(){
        $("#username").keydown(function(e){
            if(e.keyCode == "32"){
                return false;
            }
        });
        $('#email').keyup(remove_mgs);
        $("#phone").keydown(isNumbericOnly);
    });
    //    $(document).ready(function(){ 
    //        $("#save_user").click(function(){  
    //            var check = $("[name='save_user']:checked").length; 
    //            if(check == 1) $("#save_user").val('true');
    //            else $("#save_user").val('false');
    //        });  
    //    }); 
</script>